package game;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GameOverPanel extends JPanel {
    private GameWindow gameWindow;

    public GameOverPanel(GameWindow gameWindow, boolean playerWon) {
        this.gameWindow = gameWindow;
        setLayout(new GridBagLayout());
        setBackground(Color.BLACK);

        JLabel resultLabel = new JLabel(playerWon ? "胜利!" : "失败!", SwingConstants.CENTER);
        resultLabel.setFont(new Font("微软雅黑", Font.BOLD, 48));
        resultLabel.setForeground(playerWon ? Color.GREEN : Color.RED);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(2, 1, 10, 10));
        buttonPanel.setOpaque(false);

        JButton restartButton = new JButton("再来一局");
        restartButton.setFont(new Font("微软雅黑", Font.BOLD, 24));
        restartButton.addActionListener(e -> gameWindow.switchToCharacterSelect());

        JButton menuButton = new JButton("返回主菜单");
        menuButton.setFont(new Font("微软雅黑", Font.BOLD, 24));
        menuButton.addActionListener(e -> gameWindow.switchToMainMenu());

        buttonPanel.add(restartButton);
        buttonPanel.add(menuButton);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.insets = new Insets(20, 0, 20, 0);

        add(resultLabel, gbc);
        add(buttonPanel, gbc);
    }
}
